package com.exonline.commons.utils;

import javax.servlet.http.HttpServletRequest;

public class LogincheckUtils {
    public static boolean checkLogin(String name, String password) {
        //一个大写字母,一个小写字母,一个数字,最少6位
        String passwordRegex = "^\\S*(?=\\S{6,})(?=\\S*\\d)(?=\\S*[A-Z])(?=\\S*[a-z])\\S*$";
        //允许数字,字母,下划线,减号
        String nameRegex = "^[a-zA-Z0-9_-]{4,16}$";
        if (name.matches(nameRegex)&&password.matches(passwordRegex)) {
            return true;
        }else {
            return false;
        }
    }
    public static boolean checkAdminLogin(String name, String password) {
        //一个大写字母,一个小写字母,一个数字,最少6位
        String passwordRegex = "^\\S*(?=\\S{6,})(?=\\S*\\d)(?=\\S*[A-Z])(?=\\S*[a-z])\\S*$";
        //姓名
        String nameRegex = "^(?:[\\u4e00-\\u9fa5·]{2,16})$";
        if (name.matches(nameRegex)&&password.matches(passwordRegex)) {
            return true;
        }else {
            return false;
        }
    }
    public static boolean checkLogin(HttpServletRequest req) {
        String name = req.getParameter("name");
        String password = req.getParameter("password");
        if (name==null||password==null) {
            return false;
        }
        //一个大写字母,一个小写字母,一个数字,最少6位
        String passwordRegex = "^\\S*(?=\\S{6,})(?=\\S*\\d)(?=\\S*[A-Z])(?=\\S*[a-z])\\S*$";
        //数字,字母,下划线,减号
        String nameRegex = "^[a-zA-Z0-9_-]{4,16}$";
        if (name.matches(nameRegex)&&password.matches(passwordRegex)) {
            return true;
        }else {
            return false;
        }
    }

    public static void main(String[] args) {
        boolean b = checkLogin("Aizacks", "Bai200506306");
        System.out.println(b);
    }
}
